package com.example.myfirstapp2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    public static final String EXTRA_MESSAGE ="com.foo.myfirstapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找到事件源
        Button btn = findViewById(R.id.button);
        //设置事件监听,采用匿名内部类实现监听事件处理
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendMessage(view);
            }
        });
    }
    public void sendMessage(View v){
        Log.i("MyDebug","响应按钮点击事件=-");
        //构建意图，从MainActivity->DisplayMessageActivity
        Intent intent = new Intent(this, DisplayMseeageActivity.class);
        //获取文本框种的数据
        EditText editText = findViewById(R.id.editTextTextPersonName);
        String message = editText.getText().toString();
        //把数据
        intent.putExtra(this.EXTRA_MESSAGE,message);
        //执行意图
        startActivity(intent);
    }
}